package com.hanlin.direct;

import com.hanlin.RabbitUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;

/**
 * 描述：Routing 之订阅模型-Direct(直连)
 *
 * @author:hl.yuan
 * @date:2021-03-13
 */
public class SendRabbitMQ {

    public static void main(String[] args) throws IOException {
        Connection connection = RabbitUtils.getConnection();
        // 获取通道
        Channel channel = connection.createChannel();
        // 创建交换机
        channel.exchangeDeclare("logs_direct","direct");
        // 发送消息
        String key = "error";

        channel.basicPublish("logs_direct",key,null,("指定的route key["+key+"]的消息").getBytes());

        RabbitUtils.closeConnection(channel,connection);
    }

}
